package cn.ihelloworld.bean;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="comentary")
@GenericGenerator(name="idGenerator", strategy="uuid")
public class Comment implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2388759461530192585L;
	
	private String id;
	private String author;
	private String content;
	private Integer audit;
	private Date createDate;
	
	private Article article;
	
	private String articleId;
	private String articleName;
	
	@Id
	@GeneratedValue(generator="idGenerator")
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	@Transient
//	@Column(name="article_id")
	public String getArticleId() {
		return articleId;
	}
	public void setArticleId(String articleId) {
		this.articleId = articleId;
	}
	public Integer getAudit() {
		return audit;
	}
	public void setAudit(Integer audit) {
		this.audit = audit;
	}
	@Column(name="create_date",columnDefinition="datatime")
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	@ManyToOne(cascade=CascadeType.REFRESH)
    @JoinColumn(name="article_id") 
	public Article getArticle() {
		return article;
	}
	public void setArticle(Article article) {
		this.article = article;
	}
	@Transient
	public String getArticleName() {
		if(articleName==null){
			return article.getTitle();
		}
		return articleName;
	}
	public void setArticleName(String articleName) {
		this.articleName = articleName;
	}

}
